app = {};

app.mainTabs = new Ext.TabPanel(
		{
			region : 'center',
			activeTab : 0,
			id : 'mainTabs',
			enableTabScroll : true,
			height : 550,
			border : false,
			frame : true,
			plugins : new Ext.ux.TabCloseMenu(),
			items : [ {
				title : "<img align='top' class='IEPNG' src='/Car4S/resource/image/ext/user.png'/>我的工作台",
				listeners : {
					activate : function() {
						Ext.getCmp('centerPanel').setTitle('Car4S -> 我的工作台');
					}
				},
				// html : "<iframe name='mainFrame' src=''
				// scrolling='auto' frameborder='0' width='100%'
				// height='100%' ></iframe>"
				html : ''
			} ]
		});

/**
 * 响应树节点单击事件
 */
app.addTab = function(url, name, menuid, pathCh, icon) {
	if (Ext.isEmpty(icon)) {
		icon = 's.gif';
	}
	var id = "tab_id_" + menuid;
	if (url == '#' || url == '') {
		Ext.Msg.alert('提示', '此菜单还没有指定请求地址,无法为您打开页面.');
		return;
	} else {
		var n = app.mainTabs.getComponent(id);
		if (!n) {
			// 如果对centerPanel进行遮罩,则可以出现阴影mainTabs
			// Ext.getCmp('centerPanel').getEl().mask('<span
			// style=font-size:12>正在加载页面,请稍等...</span>', 'x-mask-loading');
			// document.getElementById('endIeStatus').click();//解决Iframe
			// IE加载不完全的问题
			// 兼容IE和FF触发.click()函数
			/**
			 * <code>
			var endIeStatus = document.getElementById("endIeStatus");
			if (document.createEvent) {
				var ev = document.createEvent('HTMLEvents');
				ev.initEvent('click', false, true);
				endIeStatus.dispatchEvent(ev);
			} else
				endIeStatus.click();
			 */
			n = app.mainTabs
					.add({
						id : id,
						title : "<img align='top' class='IEPNG' src='/Car4S/resource/image/ext/"
								+ icon + "'/>" + name,
						closable : true,
						layout : 'fit',
						listeners : {
							activate : function() {
								Ext.getCmp('centerPanel').setTitle(pathCh);
							}
						},
						html : '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src='
								+ url + '></iframe>'
					});
		}
		app.mainTabs.setActiveTab(n);
	}
};

Ext
		.onReady(function() {
			Ext.BLANK_IMAGE_URL = '/Car4S/resource/image/ext/s.gif';
			Ext.QuickTips.init();
			Ext.form.Field.prototype.msgTarget = 'qtip';

			new Ext.Viewport(
					{
						layout : 'border',
						items : [
								{
									xtype : 'panel',
									region : 'north',
									height : 90,
									anchor : '100%',
									margins : '0 0 0 0',
									border : false,
									layout : 'fit',
									title : 'Car4S:',
									collapsible : true,
									animCollapse : true,
									split : false,
									html : '<div style="background-color:#6699cc;">'
											+ '<table width="100%" height="90" style="border-style:outset;border:2px solid #8cb1da;">'
											+ '<tr ><td id="head_td" valign="top">'
											+ '<img src="/Car4S/resource/desktop/images/top-header.png">'
											+ '<font size="5" color="#FFFFFF">汽车4S店管理系统<font>'
											+ '</td>'
											+ '<td width="150px" align="center" valign="top">'
											+ '<div id="welcomMessage"/></td>'
											+ '</tr></table>' + '</div>'
								}, {
									region : 'center',
									id : 'centerPanel',
									iconCls : '',
									title : 'G4Studio',
									autoScroll : false,
									layout : 'fit',
									items : [ app.mainTabs ]
								}, {
									region : 'south',
									height : 26,
									frame : true,
									bodyStyle : 'text-align:center;',
									html : '<p>版本&nbsp;201311V</p>'
								}, {
									region : 'west',
									width : 220,
									collapsible : true,
									minSize : 200,
									maxSize : 350,
									split : true,
									// collapseMode:'mini',
									iconCls : 'book_previousIcon',
									title : '系统导航',
									layout : 'accordion',
									layoutConfig : {
										animate : true,
										activeOnTop : false
									},
									items : [ {
										autoScroll : true,
										border : false,
										contentEl : 'div.card.0104',
										iconCls : 'configIcon',
										title : '售后维修'
									}, {
										autoScroll : true,
										border : false,
										contentEl : 'div.card.0103',
										iconCls : 'configIcon',
										title : '客户管理'
									}, {
										autoScroll : true,
										border : false,
										contentEl : 'div.card.0105',
										iconCls : 'configIcon',
										title : '库存管理'
									}, {
										autoScroll : true,
										border : false,
										contentEl : 'div.card.0102',
										iconCls : 'configIcon',
										title : '基础数据'
									}, {
										autoScroll : true,
										border : false,
										contentEl : 'div.card.0101',
										iconCls : 'folder_wrenchIcon',
										title : '系统管理'
									} ]
								} ]
					});
		});

function showHelloMessage(username) {
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth();
	month = (month + 1) < 10 ? (month + 1) : (month + 1);
	var day = date.getDate();
	day = day < 10 ? '0' + day : day;

	var weekAry = new Array("星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	var week = weekAry[date.getDay()];

	var hour = date.getHours();
	hour = hour < 10 ? '0' + hour : hour;
	var minute = date.getMinutes();
	minute = minute < 10 ? '0' + minute : minute;
	var second = date.getSeconds();
	second = second < 10 ? '0' + second : second;
	var welcomMessage = "<div style='filter: Shadow(Color=#666699, strength=6  Direction=200);'>"
			+ "<font size='2'   color='#FFFFFF'>"
			+ year
			+ '-'
			+ month
			+ '-'
			+ day
			+ '&nbsp;&nbsp;'
			+ "<font size='2'  color='#FFFFFF'>"
			+ hour
			+ ':'
			+ minute
			+ ':'
			+ second
			+ '</font><br/>'
			+ week
			+ "<br/>"
			+ username + '，您好!</font></div>';
	document.getElementById('welcomMessage').innerHTML = welcomMessage;
}

Ext.EventManager.on(window, 'load', function() {
	/**
	 * 设置欢迎信息 Begin
	 */
	var username = '用户';

	setInterval("showHelloMessage('" + username + "')", 1000);

	setMenuTree();
	/**
	 * 设置欢迎信息 End
	 */
	setTimeout(function() {
		Ext.get('loading').remove();
		Ext.get('loading-mask').fadeOut({
			remove : true
		});
	}, 200);

});

/**
 * 取消阴影(当子页面加载完成后通过parent.XXXX来调用)
 */
function unmaskCenterPanel() {
	// 如果对centerPanel进行遮罩,则可以出现阴影
	Ext.getCmp('centerPanel').getEl().unmask();
}

// 解决Iframe IE加载不完全的问题
function endIeStatus() {
}

function setMenuTree() {
	/**
	 * <code>
	 * ---------------------------------------------------------------系统管理-------------------------------------------------------
	 */
	var node_0101 = new Ext.tree.TreeNode({
		text : '系统管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : false,
		iconCls : 'folder_wrenchIcon',
		id : 'id_node_0101'
	});
	var node_010101 = new Ext.tree.TreeNode({
		text : '权限管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : true,
		id : 'id_node_010101'
	});
	var node_01010101 = new Ext.tree.TreeNode({
		text : '用户管理',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/system/admin/userManager.jsp', '用户管理',
						'01010101', '系统管理 -> 权限管理 -> 用户管理',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01010101'
	});

	node_0101.appendChild(node_010101);
	node_010101.appendChild(node_01010101);
	var treePanel_0101 = new Ext.tree.TreePanel({
		autoHeight : false,
		autoWidth : false,
		autoScroll : false,
		animate : false,
		rootVisible : false,
		// useArrows : true,
		lines : true,
		title : '',
		border : false,
		containerScroll : true,
		applyTo : 'div.card.0101',
		root : node_0101
	});
	/**
	 * <code>
	 * ---------------------------------------------------------------系统管理-------------------------------------------------------
	 */

	/**
	 * <code>
	 * ---------------------------------------------------------------基础数据-------------------------------------------------------
	 */
	var node_0102 = new Ext.tree.TreeNode({
		text : '基础数据管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : false,
		iconCls : 'folder_wrenchIcon',
		id : 'id_node_0102'
	});
	var node_010201 = new Ext.tree.TreeNode({
		text : '基础数据',
		listeners : {
			'click' : function() {
			}
		},
		expanded : true,
		id : 'id_node_010201'
	});
	var node_01020101 = new Ext.tree.TreeNode({
		text : '预约方式',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/reserveType.jsp', '预约方式',
						'01020101', '基础数据 -> 预约方式', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020101'
	});
	var node_01020102 = new Ext.tree.TreeNode({
		text : '维修类别',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '维修类别',
						'01020102', '基础数据 -> 维修类别', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020102'
	});
	var node_01020103 = new Ext.tree.TreeNode({
		text : '牌照类型',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/carTagType.jsp', '牌照类型',
						'01020103', '基础数据 -> 牌照类型', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020103'
	});
	var node_01020104 = new Ext.tree.TreeNode({
		text : '工种类型',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/jobsType.jsp', '工种类型',
						'01020104', '基础数据 -> 工种类型', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020104'
	});
	var node_01020105 = new Ext.tree.TreeNode({
		text : '车间类型',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/workShopType.jsp', '车间类型',
						'01020105', '基础数据 -> 车间类型', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020105'
	});
	var node_01020106 = new Ext.tree.TreeNode({
		text : '付费类型',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/payType.jsp', '付费类型', '01020106',
						'基础数据 -> 付费类型', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01020106'
	});

	node_0102.appendChild(node_010201);
	node_010201.appendChild(node_01020101);
	node_010201.appendChild(node_01020102);
	node_010201.appendChild(node_01020103);
	node_010201.appendChild(node_01020104);
	node_010201.appendChild(node_01020105);
	node_010201.appendChild(node_01020106);
	var treePanel_0102 = new Ext.tree.TreePanel({
		autoHeight : false,
		autoWidth : false,
		autoScroll : false,
		animate : false,
		rootVisible : false,
		// useArrows : true,
		lines : true,
		title : '',
		border : false,
		containerScroll : true,
		applyTo : 'div.card.0102',
		root : node_0102
	});
	/**
	 * <code>
	 * ---------------------------------------------------------------基础数据-------------------------------------------------------
	 */
	/**
	 * <code>
	 * ---------------------------------------------------------------客户管理-------------------------------------------------------
	 */
	var node_0103 = new Ext.tree.TreeNode({
		text : '客户管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : false,
		iconCls : 'folder_wrenchIcon',
		id : 'id_node_0103'
	});
	var node_010301 = new Ext.tree.TreeNode({
		text : '客户管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : true,
		id : 'id_node_010301'
	});
	var node_01030101 = new Ext.tree.TreeNode({
		text : '客户信息',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/customer/customerManage.jsp', '客户信息',
						'01030101', '客户管理 -> 客户信息', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01030101'
	});

	node_0103.appendChild(node_010301);
	node_010301.appendChild(node_01030101);
	var treePanel_0103 = new Ext.tree.TreePanel({
		autoHeight : false,
		autoWidth : false,
		autoScroll : false,
		animate : false,
		rootVisible : false,
		// useArrows : true,
		lines : true,
		title : '',
		border : false,
		containerScroll : true,
		applyTo : 'div.card.0103',
		root : node_0103
	});
	/**
	 * <code>
	 * ---------------------------------------------------------------客户管理-------------------------------------------------------
	 */

	/**
	 * <code>
	 * ---------------------------------------------------------------维修业务-------------------------------------------------------
	 */
	var node_0104 = new Ext.tree.TreeNode({
		text : '维修业务管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : false,
		iconCls : 'folder_wrenchIcon',
		id : 'id_node_0104'
	});
	var node_010401 = new Ext.tree.TreeNode({
		text : '维修业务',
		listeners : {
			'click' : function() {
			}
		},
		expanded : true,
		id : 'id_node_010401'
	});
	var node_01040101 = new Ext.tree.TreeNode({
		text : '业务导航',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/repair/repair_main.jsp', '维修业务导航',
						'01040101', '售后维修->维修业务 -> 维修业务导航',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040101'
	});
	var node_01040102 = new Ext.tree.TreeNode({
		text : '车辆预约',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/repair/repairCLYY.jsp', '车辆预约',
						'01040102', '售后维修->维修业务 -> 车辆预约',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040102'
	});
	var node_01040103 = new Ext.tree.TreeNode({
		text : '车辆登记',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/repair/repairCLDJ.jsp', '车辆登记',
						'01040103', '售后维修->维修业务 -> 车辆登记',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040103'
	});
	var node_01040104 = new Ext.tree.TreeNode({
		text : '估价派工',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/repair/repairGJPG.jsp', '估价派工',
						'01040104', '售后维修->维修业务 -> 估价派工',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040104'
	});
	var node_01040105 = new Ext.tree.TreeNode({
		text : '维修出库',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '维修出库',
						'01040105', '售后维修->维修业务 -> 维修出库',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040105'
	});
	var node_01040106 = new Ext.tree.TreeNode({
		text : '配件领用',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '配件领用',
						'01040106', '售后维修->维修业务 -> 配件领用',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040106'
	});
	var node_01040107 = new Ext.tree.TreeNode({
		text : '完工质检',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '完工质检',
						'01040107', '售后维修->维修业务 -> 完工质检',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040107'
	});
	var node_01040108 = new Ext.tree.TreeNode({
		text : '维修结算',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '维修结算',
						'01040108', '售后维修->维修业务 -> 维修结算',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040108'
	});
	var node_01040109 = new Ext.tree.TreeNode({
		text : '客服回访',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/common/repairType.jsp', '客服回访',
						'01040109', '售后维修->维修业务 -> 客服回访',
						'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01040109'
	});

	node_0104.appendChild(node_010401);
	node_010401.appendChild(node_01040101);
	node_010401.appendChild(node_01040102);
	node_010401.appendChild(node_01040103);
	node_010401.appendChild(node_01040104);
	node_010401.appendChild(node_01040105);
	node_010401.appendChild(node_01040106);
	node_010401.appendChild(node_01040107);
	node_010401.appendChild(node_01040108);
	node_010401.appendChild(node_01040109);
	var treePanel_0104 = new Ext.tree.TreePanel({
		autoHeight : false,
		autoWidth : false,
		autoScroll : false,
		animate : false,
		rootVisible : false,
		// useArrows : true,
		lines : true,
		title : '',
		border : false,
		containerScroll : true,
		applyTo : 'div.card.0104',
		root : node_0104
	});
	/**
	 * <code>
	 * ---------------------------------------------------------------维修业务-------------------------------------------------------
	 */

	/**
	 * <code>
	 * ---------------------------------------------------------------库存管理-------------------------------------------------------
	 */
	var node_0105 = new Ext.tree.TreeNode({
		text : '库存管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : false,
		iconCls : 'folder_wrenchIcon',
		id : 'id_node_0105'
	});
	var node_010501 = new Ext.tree.TreeNode({
		text : '库存管理',
		listeners : {
			'click' : function() {
			}
		},
		expanded : true,
		id : 'id_node_010501'
	});
	var node_01050101 = new Ext.tree.TreeNode({
		text : '零件管理',
		listeners : {
			'click' : function() {
				app.addTab('/Car4S/app/stock/carPartsManage.jsp', '零件管理',
						'01050101', '库存管理 -> 零件管理', 'chart_organisation.png');
			}
		},
		expanded : false,
		iconCls : 'chart_organisationIcon',
		id : 'id_node_01050101'
	});

	node_0105.appendChild(node_010501);
	node_010501.appendChild(node_01050101);
	var treePanel_0105 = new Ext.tree.TreePanel({
		autoHeight : false,
		autoWidth : false,
		autoScroll : false,
		animate : false,
		rootVisible : false,
		// useArrows : true,
		lines : true,
		title : '',
		border : false,
		containerScroll : true,
		applyTo : 'div.card.0105',
		root : node_0105
	});
	/**
	 * <code>
	 * ---------------------------------------------------------------库存管理-------------------------------------------------------
	 */
}
